//
//  MyTableViewCell.m
//  NuwaRobot
//
//  Created by Kendama on 2017/11/30.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "MyTableViewCell.h"
#import "InfraredModel.h"

NSString *const kMyTableViewCellIdentifier = @"kMyTableViewCellIdentifier";

@implementation MyTableViewCell

+ (instancetype)dequeueReusableWithTableView:(UITableView *)tableView
{
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kMyTableViewCellIdentifier];
    if (cell == nil)
    {
        cell = [[MyTableViewCell alloc]init];
    }
    return cell;
}

- (instancetype)init
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kMyTableViewCellIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = cellBackgroundColor;
        [self masLayoutSubview];
    }
    return self;
}

- (void)setInfraredModel:(InfraredModel *)infraredModel
{
    _infraredModel = infraredModel;
    _titleLabel.text = infraredModel.name;
    if ([infraredModel.type isEqualToString:@"2"])
    {
        _iconImageView.image = imageWithName(@"icon_TV");
    }
    else if ([infraredModel.type isEqualToString:@"7"])
    {
        _iconImageView.image = imageWithName(@"icon_airconditioner");
    }
    else
    {
        _iconImageView.image = imageWithName(@"icon_STB");
    }
}

- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        UIView *superView = self.contentView;
        _iconImageView = [[UIImageView alloc]init];
        [superView addSubview:_iconImageView];
    }
    return _iconImageView;
}
- (UILabel *)titleLabel
{
    if(!_titleLabel)
    {
        UIView *superView = self.contentView;
        _titleLabel = [[UILabel alloc]init];
        [superView addSubview:_titleLabel];
        [_titleLabel setFont:fontCommonSize];
        [_titleLabel setTextColor:[UIColor whiteColor]];
    }
    return _titleLabel;
}

- (UIImageView *)rightImageView
{
    if(!_rightImageView)
    {
        UIView *superView = self.contentView;
        _rightImageView = [[UIImageView alloc]init];
        [superView addSubview:_rightImageView];
        _rightImageView.image = [UIImage imageNamed:@"enter"];
    }
    return _rightImageView;
}



- (void)masLayoutSubview
{
    __weak UIView *superView = self.contentView;
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.left.mas_equalTo(superView.mas_left).with.offset(px1920Height(40));
        make.height.width.mas_equalTo(px1920Height(40));
    }];
    
    [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.right.mas_equalTo(superView.mas_right).with.offset(-px1920Height(40));
        make.height.mas_equalTo(px1920Height(35));
        make.width.mas_equalTo(px1920Height(20));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.left.mas_equalTo(self.iconImageView.mas_right).with.offset(px1920Height(40));
        make.right.mas_equalTo(self.rightImageView.mas_left).with.offset(-px1920Height(40));
    }];
    
    
    UIView *lineView = ({
        lineView = [[UIView alloc]init];
        [superView addSubview:lineView];
        lineView.backgroundColor = rgba(6,27,56,1);
        [lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(superView.mas_bottom);
            make.left.right.mas_equalTo(superView);
            make.height.mas_equalTo(px1920Height(1));
        }];
        lineView;
        
    });
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
